//
//  WeatherThirdScrollView.m
//  weather
//
//  Created by 大L君的无敌战舰 on 16/4/12.
//  Copyright © 2016年 bigL.com. All rights reserved.
//

#define ViewWidth ([UIScreen mainScreen].bounds.size.width / 9 * 24)

#import "WeatherThirdScrollView.h"

@interface WeatherThirdScrollView ()
/* 保存btn模型 */
@property (strong, nonatomic) NSMutableArray * lableArray;
/* 创建容器View */
@property (strong, nonatomic) UIView *containView;
/* 创建创建顶部控制View */
@property (strong, nonatomic) UIView *topView;
/* 创建底部容器View */
@property (strong, nonatomic) UIView *botContainView;
/* 创建底部显示View */
@property (strong, nonatomic) UIView *botView;
@end

@implementation WeatherThirdScrollView

-(NSMutableArray *)lableArray
{
    if (!_lableArray) {
        _lableArray = [NSMutableArray array];
    }
    return _lableArray;
}

//初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //当前View的配置信息
        [self selfConfigurationInformation];
        //加载子控件
        [self setChildView];
    }
    return self;
}

//当前View的配置信息
- (void)selfConfigurationInformation
{
    //设置内边距
    self.contentSize = CGSizeMake(BLScreenSize.width / 6 * 16, 0);
    //设置背景颜色
    self.backgroundColor = [UIColor clearColor];
    //隐藏滑动条
    self.showsVerticalScrollIndicator = NO;
    self.showsHorizontalScrollIndicator = NO;
}


-(void)setChildView
{
    //创建容器View
    UIView *containView = [[UIView alloc]init];
    self.containView = containView;
    [self addSubview:containView];
    containView.backgroundColor = BLRandomColor(2);
    
    //创建顶部控制View
    UIView *topView = [[UIView alloc]init];
    self.topView = topView;
    [self.containView addSubview:topView];
    topView.backgroundColor = BLRandomColor(2);
    
    //创建底部容器View
    UIView *botContainView = [[UIView alloc]init];
    self.botContainView = botContainView;
    [self.containView addSubview:botContainView];
    botContainView.backgroundColor = BLRandomColor(2);
    
    
    //创建底部显示View
    UIView *botView = [[UIView alloc]init];
    self.botView = botView;
    [botContainView addSubview:botView];
    
    //创建24个时间Label
    for (NSInteger i = 0; i<24; i++) {
        UILabel * timeLabel = [[UILabel alloc]init];
        timeLabel.text                      = [NSString stringWithFormat:@"20:0%ld",i];
        timeLabel.font                      = TextSmallSize;
        timeLabel.textColor                 = [UIColor whiteColor];
        timeLabel.textAlignment             = NSTextAlignmentCenter;
        timeLabel.adjustsFontSizeToFitWidth = YES;
        timeLabel.userInteractionEnabled    = YES;
        [self.botView addSubview:timeLabel];
        [self.lableArray addObject:timeLabel];
    }
}

-(void)layoutSubviews
{
    //!!!: 调用太频繁
    [super layoutSubviews];
    
   self.containView.frame = CGRectMake(0, 0, ViewWidth, self.height);
    self.topView.frame = CGRectMake(0, 0, ViewWidth, self.height * 0.2);
    self.botContainView.frame = CGRectMake(0,self.height * 0.2, ViewWidth, self.height *0.8);
    self.botView.frame = CGRectMake(0, 0,ViewWidth, self.height * 0.8);



    
    CGFloat width  = BLScreenSize.width / 9;
    CGFloat height = self.botView.height * 0.2;
    CGFloat x      = 0;
    CGFloat y      = self.botView.height - height;
    for (NSInteger i = 0; i < self.self.lableArray.count; i++) {
        UILabel *label = self.lableArray[i];
        x = width  * i;
        label.frame = CGRectMake(x, y, width, height);
        //BLog(@"%ld ---- %@",i,NSStringFromCGPoint(label.frame.origin));
    }
    
    
}

@end
